#include "MainFrame/SettingDock/BrushesDock.h"
#include "UI/FlowLayout.h"

#include <QToolButton>

#include "IRIVIABrushes.h"

BrushesDock::BrushesDock(const QString &title, QWidget *parent, Qt::WindowFlags flags):
    QDockWidget(title, parent, flags),
    m_pBrushesDockWidget(nullptr),
    m_pFlowLayout(nullptr),
    m_pPixelButton(nullptr),
    m_pBlockButton(nullptr),
    m_pHardnessButton(nullptr)
{
    setFeatures(DockWidgetFloatable | DockWidgetMovable);
    this->setMinimumWidth(300);
    this->setMaximumWidth(500);
    this->setMaximumHeight(200);
    initSettingWidget();
    connetSignalToSlots();
}

BrushesDock::~BrushesDock()
{

}

void BrushesDock::PixelButtonSlot()
{
    IRIVIABrushes().setCurBrush("Pixel");
}

void BrushesDock::BlockButtonSlot()
{
    IRIVIABrushes().setCurBrush("Block");
}

void BrushesDock::HardnessButtonSlot()
{
    IRIVIABrushes().setCurBrush("Hardness");
}

void BrushesDock::initSettingWidget()
{
    QWidget* m_pBrushesDockWidget = new QWidget(this);
    this->setWidget(m_pBrushesDockWidget);

    FlowLayout *m_pFlowLayout = new FlowLayout;
    m_pBrushesDockWidget->setLayout(m_pFlowLayout);

    m_pPixelButton = addToolButton("Pixel");
    m_pFlowLayout->addWidget(m_pPixelButton);
    m_pPixelButton->setChecked(true);

    m_pBlockButton = addToolButton("Block");
    m_pFlowLayout->addWidget(m_pBlockButton);

    m_pHardnessButton = addToolButton("Hardness");
    m_pFlowLayout->addWidget(m_pHardnessButton);

}

void BrushesDock::connetSignalToSlots()
{
    connect(m_pPixelButton, SIGNAL(clicked()), this, SLOT(PixelButtonSlot()));
    connect(m_pBlockButton, SIGNAL(clicked()), this, SLOT(BlockButtonSlot()));
    connect(m_pHardnessButton, SIGNAL(clicked()), this, SLOT(HardnessButtonSlot()));
}

QToolButton *BrushesDock::addToolButton(const QString &brushname)
{
    QToolButton* button = new QToolButton(m_pBrushesDockWidget);
    button->setIconSize(QSize(50,50));
    button->setToolTip(brushname);
    button->setAutoExclusive(true);
    button->setCheckable(true);
    button->setIcon(QIcon(":/Icons/Brushes/" + brushname + ".png"));
    return button;
}
